package com.sun.showcase.controller.mall;

import com.sun.showcase.biz.mall.service.PosterService;
import com.sun.showcase.client.domain.mall.Poster;
import com.sun.showcase.client.query.mall.PosterQuery;
import com.sun.showcase.pojo.DataGrid;
import com.sun.showcase.pojo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping(value="/mall/poster")
public class PosterController{
	
	@Autowired
	private PosterService posterService;
	
	private Result result = new Result();
	/**
	 * 跳转到Poster管理页面
	 * 
	 * @return
	 */
	@RequestMapping(value="goPoster")
	public String goPoster() {
		posterService.get();
		return "mall/poster";
	}
	/**
	 * 跳转到Poster新增页面
	 * 
	 * @return
	 */
	@RequestMapping(value="handlePoster")
	public String handlePoster(@RequestParam(value="id",required=false) Long id , ModelMap map) {
		return "mall/poster_rowEdit";
	}

	/**
	 * 跳转到查看desc页面
	 * 
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="showDesc")
	public Poster showDesc(PosterQuery posterQuery) {
		return posterService.get(posterQuery);
	}

	/**
	 * 获得分页数据表格
	 */
	@ResponseBody
	@RequestMapping(value = "/datagrid")
	public DataGrid datagrid(PosterQuery posterQuery) {
		return posterService.datagrid(posterQuery);
	}
	

	/**
	 * 添加一个Poster
	 */
	@ResponseBody
	@RequestMapping(value="add")
	public Result add(PosterQuery posterQuery) {
		posterService.add(posterQuery);
		result.setSuccess(true);
		result.setMsg("添加成功！");
		return result;
	}

	/**
	 * 编辑Poster
	 */
	@ResponseBody
	@RequestMapping(value="edit")
	public Result edit(PosterQuery posterQuery) {
		posterService.update(posterQuery);
		result.setSuccess(true);
		result.setMsg("编辑成功！");
		return result;
	}

	/**
	 * 物理删除Poster
	 */
	@ResponseBody
	@RequestMapping(value="delete")
	public Result delete(PosterQuery posterQuery) {
		posterService.delete(posterQuery.getIds());
		result.setSuccess(true);
		result.setMsg("删除成功！");
		return result;
	}
	
	/**
	 * 逻辑删除Poster
	 */
	@ResponseBody
	@RequestMapping(value="deletePt")
	public Result deletePt(PosterQuery posterQuery) {
		posterService.deletePt(posterQuery.getIds());
		result.setSuccess(true);
		result.setMsg("删除成功！");
		return result;
	}
	/**
	 * 全部数据Poster
	 */
	@ResponseBody
	@RequestMapping(value="listAll")
	public Result listAll(PosterQuery posterQuery) {
		List<PosterQuery> list = posterService.listAll(posterQuery);
		result.setSuccess(true);
		result.setMsg("成功！");
		result.setData(list);
		return result;
	}
	/**
	 * 全部数据Poster
	 */
	@ResponseBody
	@RequestMapping(value="get")
	public Result get(PosterQuery posterQuery) {
		result.setSuccess(true);
		result.setMsg("成功！");
		result.setData(posterService.get("1"));
		return result;
	}
}
